using System;
using System.Linq;
using System.Text;
using PropertyExpression.Common;

namespace PropertyExpression.PresentationCode.CodeGenerator
{
    internal class OverloadedMethodBuilderByConstructor : IOverloadedMethodBuilder
    {
        public void Build(StringBuilder stringBuilder, Type parameterType, IOverloadedAndPrefixMethodsBuilder overloadedAndPrefixMethodsBuilder)
        {
            foreach (var constructorInfo in parameterType.GetConstructors())
            {
                var parameters = constructorInfo.GetParameters();
                if (parameters.Length > 0)
                {
                    if (parameters.Where(info => info.ParameterType.IsPointer).Count() == 0)
                    {
                        overloadedAndPrefixMethodsBuilder.BuildOverloadedMethods(
                            parameterType,
                            stringBuilder,
                            parameters.Select(parameterInfo =>
                                              string.Format("{0} {1}", parameterInfo.ParameterType,
                                                            parameterInfo.Name)).Join(", "),
                            parameters.Select(parameterInfo => parameterInfo.Name).Join(", "));
                    }
                }
            }
        }
    }
}